package org.opens.mybatisplus.controller;

import org.opens.mybatisplus.dao.FormatDao;
import org.opens.mybatisplus.pojo.FormatPojo;
import org.opens.mybatisplus.pojo.result.ResultBean;
import org.opens.mybatisplus.service.FormatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/double")
public class FormatController {

    @Autowired
    private FormatDao formatDao;

    @Autowired
    private FormatService formatService;

    @GetMapping(value = "/format")
    public ResultBean<List<FormatPojo>> getDate() {
        List<FormatPojo> date = formatDao.selectByMap(null);
        return ResultBean.success(date);
    }

    /**
     * 功能:
     *      -简介
     *          1. service中实现了DO和java程序的半解耦, 通过lombok.
     * @param id
     * @param name
     * @return
     */
    @GetMapping(value = "/decoupling")
    public ResultBean doDecoupling(
            @RequestParam(value = "id", defaultValue = "0") int id,
            @RequestParam(value = "name", defaultValue = "") String name
    ) {
        return ResultBean.success(formatService.selectOneByIdAndName(id, name));
    }

}
